import java.io.File;
import java.io.FileNotFoundException;


public class Scanner {

	private Token[] tokens;
	private int tokenIndex;
	public Scanner(String spec, String file) {
		tokenIndex = 0;
		try {
			DFA dfa = ScannerGenerator.dfaFromLexicalSpec(spec);
			tokens = dfa.tokenize(new java.util.Scanner(new File(file)));
		} catch (FileNotFoundException e) {
			tokens = new Token[0];
			System.out.println("File not found.");
		}
	}
	
	public Token getNextToken() {
		if(tokens == null || tokenIndex == tokens.length)
			return null;
		return tokens[tokenIndex++];
	}
	
	public Token[] getAllTokens(){ return tokens.clone();}

}
